//
// Created by fanghr on 18-3-24.
//

#ifndef ACCLSEN_ACCLEN_DATA_H
#define ACCLSEN_ACCLEN_DATA_H

#include <array>
#include <cinttypes>
#include <pthread.h>

namespace acclsen_recv {
    class acclsen_data_exception {
    public:
        enum err_code {
            SUM_FAIL,
            WRONG_SOURCE,
        };

        static acclsen_data_exception make(err_code code) {
            return acclsen_data_exception(code);
        }

        err_code get() {
            return code;
        }

    private:
        err_code code;

        explicit acclsen_data_exception(err_code code) : code(code) {}

    public:
        static bool check_sum(const std::array<uint8_t, 11> &source) {
            long sum = 0;
            for (auto i = 0; i < 10; i++)
                sum += source[i];
            return sum == source[10];
        }

        static bool check_type(const std::array<uint8_t, 11> &source, uint8_t type) {
            return source[1] == type;
        }

    };

    struct time {
        long y, m, d, h, s, ms;

        time(const std::array<uint8_t, 11> &source);
    };

    struct acc {
        double ax, ay, az, t;

        acc(std::array<uint8_t, 11> &source);
    };

    struct angsp {
        double wx, wy, wz, t;

        angsp(std::array<uint8_t, 11> &source);
    };

    struct ang {
        double roll, pitch, yaw, t;

        ang(std::array<uint8_t, 11> &source);
    };

    struct magf {
        double hx, hy, hz, t;

        magf(std::array<uint8_t, 11> &source);
    };

    struct port {
        long d0, d1, d2, d3;

        port(std::array<uint8_t, 11> &source);
    };

    struct prehei {
        long P, H;

        prehei(std::array<uint8_t, 11> &source);
    };

    struct latlon {
        long lon, lat;

        latlon(std::array<uint8_t, 11> &source);
    };

    struct grsp {
        long gpsheight, gpsyaw, gpsv;

        grsp(std::array<uint8_t, 11> &source);
    };

    struct foel {
        long q0, q1, q2, q3;

        foel(std::array<uint8_t, 11> &source);
    };

    struct spa {
        long sn, pdop, hdop, vdop;

        spa(std::array<uint8_t, 11> &source);
    };
}
#endif //ACCLSEN_ACCLEN_DATA_H
